home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
.net (French) 1996 November
/
.net Magazine (FR) - Issue 01 - Nov 1996.iso
/
mac
/
Butineur
/
Netscape Plug-ins
/
KM's QuickTime plug
/
Sources
/
MoviePlug9.p
< prev
next >
Wrap
Text File
|
1996-02-05
|
29KB
|
847 lines
{My movie plugin made from Netscape's shell file from the New SDK 0.7.
Interface bugs are probably mine, not Netscape's.
This project has some trouble with Netscape's windows either by my bugs or Netscape's.
Expect to see winow updating flaws.
Kevin McMurtrie mcmurtri@wco.com
2/5/95, AKA 0.2.0}
{$D-}
unit ViewPict;
interface
uses npapi;
function NPP_Initialize:NPError;
procedure NPP_Shutdown;
function NPN_MemAlloc (size: longint):Ptr; C; EXTERNAL;
procedure NPN_MemFree (buf: Ptr); C; EXTERNAL;
function NPP_New (pluginType:NPMIMEType;
var instance:NPP;
mode: integer;
argc: integer;
argn: arglist;
argv: arglist;
recalled: NPSavedDataPtr):NPError;
function NPP_Destroy (var instance:NPP; var save: NPSavedDataPtr):NPError;
function NPP_SetWindow (var instance: NPP; NwindowP: NPWindowPtr): NPError;
function NPP_NewStream (var instance: NPP;
Mtype: NPMIMEType;
var stream: NPStream;
seekable: boolean;
var stype: integer):NPError;
function NPP_WriteReady (var instance: NPP; var stream: NPStream):longint;
function NPP_Write (var instance: NPP; var stream: NPStream; offset, len: longint; buffer: Ptr):longint;
function NPP_DestroyStream (var instance: NPP; var stream: NPStream; reason: NPError):NPError;
procedure NPP_StreamAsFile (var instance: NPP; var stream: NPStream; fname: charstar);
procedure NPP_Print (var instance: NPP; var printInfo: NPPrint);
function NPP_HandleEvent (var instance: NPP; var event: EventRecord):integer;
implementation
uses npapi, Windows, Speech,Movies, Fonts, TextUtils, ImageCompression, GestaltEqu, Resources;
var
{$J+}
gResFile: integer;EXTERNAL; {Global variable in pascal_npmac.cpp that is my resource ref ID#}
{$J-}
Type
SavedDataT = record {This is information that is saved at Destroy and recalled at New}
LastTime:TimeValue;
LastRate:Fixed;
LastVol: integer; {16 bit fixed}
end;
SavedDataPtrT = ^SavedDataT; {This is a pointer-type to the data used for storage across Destroy and New}
OptionsT = record {Options used when opening/displaying the movie}
CX, CY : boolean; {Auto center h and v placement}
F: boolean; {Force fit to rect}
AL, AT: boolean; {If not CX/CY or F then manual align Left/Right and Top/Bottom}
CS: (Auto, Visible, Hidden, None, Badge); {Controller usage}
PlayRate: Fixed; {Initial play rate (32bit fixed) }
LP: (Once, Linear, Palidrome); {No loop, loop linear, loop palidrome}
Vol: integer; {Movie volume (16 bit fixed) }
MediaKind: char; {What kind of a movie this is. From my resource. (A-audio, V-video, S-still) }
Slide: boolean; {Slideshow mode - play all frames, no sound}
HighQ:boolean; {High quality (slow!!) }
UsePalette:boolean; {Use movie's custom palette for whole window}
StartPosition: TimeValue; {This is used for recalling the last position before Destroy, may later HTML option too}
end;
GraphicsStateT = record {Saved drawing states. Set by SetupDrawState for RestoreDrawState.}
SPort: GrafPtr; {The port that was previously in use}
SOrigin: Point; {To watch for any motion of window contents. Set by SetupDrawState for SetupDrawState.}
SWMOrigin: Point; {Window Manager's previous origin. Set by SetupDrawState for RestoreDrawState.}
DidSave:boolean; {The info here is valid. Set by SetupDrawState for RestoreDrawState.}
PortChanged: boolean; {The grafport changed. Set by the procedure changing the port for SetupDrawState.}
end;
MyDataT = record {This is all the data associated with a plug-in instance}
NWindP: NPWindowPtr; {Netscape window}
check1: ^NP_Port; {check1 and check2 are for testing the validity of Netscape's window data╔ }
check2: CGrafPtr; { ╔a bug causes corrupt data during update events}
Loaded: boolean; {Are we done loading?}
TheFile: FSSpec; {Location of file on disk}
MacFileType:OSType; {Type of file - MooV, WAVE, etc. Set when stream is created}
MovFileRef: integer; {Movie's reference to the file}
Mov: Movie; {The movie}
MovContr: ComponentInstance; {The controller}
TempRegion: RgnHandle; {Premade RgnHandle - Used for masking or whatever needs a quick RgnHandle for temporary calculations.}
GraphicsState: GraphicsStateT; {Window and graphics saved states}
Options: OptionsT; {HTML options}
end;
MyDataP = ^MyDataT;
function Corruption (var dat: MyDataT): boolean; {Has Netscape magicly changed the window param storage to garbage?}
begin
with dat do if (NWindP<>nil) then Corruption:= (check1 <> NWindP^.window) | (check2 <> NWindP^.window^.port)
else Corruption:=false;
end;
procedure WhatIsIt (var MimeKind:Str255; var MacType:OSType; var MediaKind:char); {What should the Mac file type be}
var {And what kind of media is it? }
i:integer;
s:Str255; {Temp string}
r:integer; {Temp resource file ID}
err:OSErr;
begin
r:=CurResFile;
err:=ResError;
UseResFile (gResFile);
err:=ResError;
i:=0;
repeat {Find index of this MIME type in my acceptance list - OK to go to end}
i:=succ(i);
GetIndString (s, 128, i*2 -1);
until (length(s)=0) or (s=MimeKind);
GetIndString (s, 129, i*2); {Get the file kind (Video Still Audio) from my matching type list}
MediaKind:=s[1];
GetIndString (s, 129, i*2 -1); {Get the Mac file type from my matching type list}
MacType[1]:= s[1]; {Return the file type}
MacType[2]:= s[2];
MacType[3]:= s[3];
MacType[4]:= s[4];
UseResFile (r);
end;
function OpenFromFile (var dat: MyDataT): OSErr; {Open the movie file specified in Mov.TheFile}
var {Translate the file if it isn't a QuickTime movie}
err, Xerr:OSErr; {err - saved error, Xerr - unsaved error}
res: integer;
changed: boolean;
info:FInfo;
begin
with dat do begin
Xerr:= OpenMovieFile(TheFile, MovFileRef, fsCurPerm); {Open the file}
res:=0;
Mov:=nil;
err:= NewMovieFromFile(Mov, MovFileRef, res, nil, newMovieActive + newMovieDontResolveDataRefs, changed); {Try opening it}
if Mov = nil then {Didn't work, must do a QT import}
begin
Xerr:= CloseMovieFile (MovFileRef); {Close & start over}
Xerr:= FSpGetFInfo (TheFile, info); {Set the cache file to the correct Mac file type}
info.fdType:= MacFileType;
info.fdFlags:= BAnd(BNot (kHasBeenInited),info.fdFlags);
err:= FSpSetFInfo (TheFile, info);
if err = noErr then
begin
err:=ConvertFileToMovieFile (TheFile, TheFile, info.fdCreator, smCurrentScript, res, 0, nil, nil, 0); {Convert}
if err = noErr then
begin
Xerr := OpenMovieFile(TheFile, MovFileRef, fsCurPerm); {Retry opening}
res:=0;
err:= NewMovieFromFile(Mov, MovFileRef, res, nil, newMovieActive + newMovieDontResolveDataRefs, changed);
if Mov <> nil then
begin
err:= UpdateMovieResource (Mov, MovFileRef, res, 'Movie data conversion'); {Save changes to avoid reconvering later}
end;
end;
end;
end; {Must do a QT import}
Xerr:= CloseMovieFile (MovFileRef); {OK to close it - no editing will be done}
end;
OpenFromFile:=err;
end;
procedure SetTheMovieSize (var dat: MyDataT); {Set the movie size based on the window info and HTML options}
const
ContHeight = 16; {Assumed size of movie controller}
MinSize = 9; {Movies < 3 pixels squared, such as sound tracks, will be resized to a controller}
var
m:MatrixRecord;
CompErr: ComponentResult;
MovBox, ContBox: Rect;
ContVis:boolean;
begin
with MovBox, dat, dat.NWindP^, dat.Options do begin
SetIdentityMatrix (m); {Take off any saved scaling}
SetMovieMatrix (Mov, m);
GetMovieBox(Mov, MovBox);
OffsetRect(MovBox, -left, -top);
if F or ((width*height) < MinSize) then {Forced size or near zero destination}
begin
ContVis:= CS=Visible; {Controller only if manually set}
right:=width; bottom:= (height - ord(ContVis)*ContHeight); {Make room for controller, if needed}
end else
begin {Auto size}
if (longint(right)*longint(bottom)) < MinSize then {Invalid dimensions - too small. Make full controller if OK}
begin
right:=width;
ContVis:= (CS=Auto) or (CS=Visible); {Visible controller, unless forced off}
end else
begin {Valid movie dimensions - scale}
ContVis:=(CS=Visible); {Is controller forced}
if (width >= (right * 2)) and (height >= (bottom*2 + ord(ContVis or (CS=Badge))*ContHeight)) then
begin right:= right * 2; bottom:= bottom * 2; end {Can zoom to X2}
else
if (width < right) or (height < (bottom + ord(ContVis or (CS=Badge))*ContHeight)) then {Must shrink to size}
begin
if (right-width) > (bottom-height) then {Keep aspect ratio}
begin {Shrink to fit x}
bottom:= (longint (bottom) * width) div right;
right:=width;
end else
begin {Shrink to fit y}
right:= (longint (right) * height) div bottom;
bottom:=height;
end;
end;
if CS=Auto then ContVis:=bottom+ContHeight <= height; {Vis if auto and room}
end;
{Set moviebox position}
if CX then OffsetRect(MovBox,(width - right) div 2, 0) {Center X}
else
if not AL then OffsetRect(MovBox, width - right, 0); {Right X}
if CY then OffsetRect(MovBox, 0, (height - (bottom+ord(ContVis or (CS=Badge))*ContHeight)) div 2) {Center Y}
else
if not AT then OffsetRect(MovBox, 0, height - (bottom+ord(ContVis or (CS=Badge))*ContHeight)); {Bottom Y}
end; {Auto sizing}
CompErr := MCSetVisible(MovContr, ContVis);
if CompErr <> noErr then SysBeep(30);
ContBox.top := bottom;
ContBox.left:= left;
ContBox.right:= right;
ContBox.bottom:= bottom + ContHeight; {The controller is always there, even if you can't see it.}
CompErr:= MCPositionController (MovContr, MovBox, ContBox, mcScaleMovieToFit+mcTopLeftMovie);
end; {With}
end;
function PrepMovie (var dat: MyDataT): OSErr; {Get the loaded movie ready for use.}
var {Pitty the person who gets all the CompErr<>noErr}
CompErr: ComponentResult;
tempRect:Rect;
err:OSErr;
begin
with dat, dat.Options do begin
GetMovieBox (Mov,tempRect);
SetMovieTimeValue (Mov, StartPosition); {Restore last playback position}
err:= PrerollMovie (Mov, StartPosition, PlayRate);
err:= LoadMovieIntoRam(Mov, 0, GetMovieDuration(Mov), loadBackwardTrackEdits + loadForwardTrackEdits + unkeepInRam); {Speed up disk access}
if HighQ then SetMoviePlayHints(Mov, hintsHighQuality, hintsHighQuality);
MovContr := NewMovieController(Mov, tempRect, mcTopLeftMovie + mcNotVisible + ord(CS=Badge)*mcWithBadge); {Attach a controller to movie}
if MovContr = nil then begin PrepMovie:= GetMoviesError; Exit (PrepMovie); end;
CompErr := MCDoAction(MovContr, mcActionSetFlags, mcFlagSuppressMovieFrame + ord4(UsePalette) * ord4(mcFlagsUseWindowPalette));
if CompErr <> noErr then SysBeep(30);
CompErr := MCDoAction(MovContr, mcActionSetPlayEveryFrame, ord4(Slide)); {Play all frames}
if CompErr <> noErr then SysBeep(30);
CompErr := MCDoAction(MovContr, mcActionSetLooping, ord4((LP=Linear) or (LP=Palidrome))); {Looping conrtol}
if CompErr <> noErr then SysBeep(30);
CompErr := MCDoAction(MovContr, mcActionSetLoopIsPalindrome, ord4(LP=Palidrome)); {Palindrome Looping control}
if CompErr <> noErr then SysBeep(30);
CompErr := MCDoAction(MovContr, mcActionSetVolume, ord4(Vol)); {Set volume}
if CompErr <> noErr then SysBeep(30);
CompErr := MCDoAction(MovContr, mcActionSetKeysEnabled, ord4(false)); {Disable control by keyboard}
if CompErr <> noErr then SysBeep(30);
CompErr := MCEnableEditing(MovContr, false); {Disable editing}
if CompErr <> noErr then SysBeep(30);
CompErr := MCDoAction(MovContr, mcActionPlay, ord4(PlayRate)); {Set play speed}
if CompErr <> noErr then SysBeep(30);
CompErr := MCDoAction(MovContr, mcActionActivate, nil); {Make sure activated}
if CompErr <> noErr then SysBeep(30);
end;
PrepMovie:=noErr;
end;
procedure CloseIt (var dat: MyDataT); {Close movie's data (but not the MyDataT itself) }
begin
if @dat = nil then Exit (CloseIt);
with dat do begin
if MovContr <> nil then DisposeMovieController(MovContr);
if Mov <> nil then DisposeMovie(Mov);
MovContr:= nil;
Mov:= nil;
Loaded:=false;
end;
end;
{ ------------------------------------------------------------------------------------
SetupDrawState: Set up port, clipping, origin, color, stuff...
Set 'printing' to true to avoid non-print compatible stuff.
------------------------------------------------------------------------------------}
function SetupDrawState (var dat:MyDataT):Boolean;
var
oldForeColor, oldBackColor: RGBColor;
CompErr: ComponentResult;
begin
if @dat = nil then begin SetupDrawState:=false; Exit (SetupDrawState); end;
with dat do if (NWindP <> nil) & (MovContr <> nil) then
begin
with GraphicsState, NWindP^.window^ do begin
GetPort (SPort); {Save and set port}
SetPort (GrafPtr(port)); {Set my port}
SWMOrigin:= port^.portRect.topLeft; {Save the Window Manager's origin}
SetOrigin (portx, porty); {Set my origin}
if (not DidSave) or (SOrigin.v <>porty) or (SOrigin.h <> portx) or PortChanged then {Window stuff changed}
begin
with NWindP^.clipRect do SetRectRgn (TempRegion, left+portx, top+porty, right+portx, bottom+porty); {Movie's window region}
if PortChanged then {NPP_SetWindow sets this to true so it catches the change}
begin
SetClip (TempRegion);
GetForeColor (oldForeColor); {Save the current colors}
GetBackColor (oldBackColor);
ForeColor (blackColor); {Normal, fast-draw, black&white}
BackColor (whiteColor);
CompErr:= MCSetControllerPort (MovContr, port); {Set new port; it uses color settings}
if CompErr <> noErr then SysBeep(30);
SetTheMovieSize (dat); {Reset the size of the movie to match the window}
RGBForeColor (oldForeColor); {Restore current colors}
RGBBackColor (oldBackColor);
InvalRgn (TempRegion); {Netscape can do this wrong so do it again...}
PortChanged:= false; {Reset value}
end;
CompErr:= MCSetClip (MovContr, TempRegion, TempRegion);
SOrigin.h:=portx; SOrigin.v:= porty;
end; {Something changed}
DidSave:= true; {Reset flags and checks}
end; {With}
end else GraphicsState.DidSave:= false; {Variables ok}
SetupDrawState:= dat.GraphicsState.DidSave;
end;
procedure RestoreDrawState (var dat:MyDataT);
begin
with dat.GraphicsState do if DidSave then
begin
SetOrigin (SWMOrigin.h, SWMOrigin.v); {Restore Window Manager's origin and current port}
SetPort (SPort);
end;
end;
procedure ControlledUpdate (var dat:MyDataT; printing:boolean); {Update the movie with the port set correctly}
var
CompErr: ComponentResult;
begin
with dat do
if SetupDrawState(dat) then
begin
CompErr:= MCDraw(MovContr, GrafPtr(NWindP^.window^.port));
RestoreDrawState (dat);
end;
end;
function ControlledMovieEvent (var dat:MyDataT; var event: EventRecord): integer; {Handle events with the port set correctly}
begin
if SetupDrawState(dat) then
begin
ControlledMovieEvent:= MCIsPlayerEvent(dat.MovContr, event);
RestoreDrawState (dat);
end else ControlledMovieEvent:=0;
end;
procedure CopyC2P (c: charstar; var p: Str255); {Non-destructive C to P string converter}
var {charstar is ^packed array [1..1] of char}
i:integer;
begin
i:=1;
while (i<=255) & (ord(c^[i]) <>0) do begin
p[i]:= c^[i];
i:= succ (i);
end;
p[0]:= char(i-1);
end;
{/------------------------------------------------------------------------------------
// NPP_Initialize:
//------------------------------------------------------------------------------------}
function NPP_Initialize: NPError;
var
result: longint; {not used}
begin
if Gestalt(gestaltQuickTime, result) = noErr then {Must have QuickTime!!!! }
begin
if EnterMovies = noErr then NPP_Initialize:=NP_NOERR else NPP_Initialize:=NPERR_MODULE_LOAD_FAILED_ERROR;
end else
NPP_Initialize:=NPERR_MODULE_LOAD_FAILED_ERROR;
end;
{/------------------------------------------------------------------------------------
// NPP_Shutdown:
//------------------------------------------------------------------------------------}
procedure NPP_Shutdown;
var
result: longint; {not used}
begin
if Gestalt(gestaltQuickTime, result) = noErr then ExitMovies; {Must have QuickTime!!!! }
end;
{/------------------------------------------------------------------------------------
// NPP_New:
Create space for data storage
//------------------------------------------------------------------------------------}
function NPP_New (pluginType: NPMIMEType;
var instance: NPP;
mode: integer;
argc: integer;
argn: arglist;
argv: arglist;
recalled: NPSavedDataPtr):NPError;
var
i:integer; {Counts through argc}
NewVol:longint; {Need a longint for a VAR param}
V,N:Str255; {Pascal strings for argn and argv}
s:Str255;
begin
instance.pdata := NPN_MemAlloc(sizeof(MyDataT)); {Make my variable space}
if instance.pdata = nil then begin NPP_New:= NPERR_OUT_OF_MEMORY_ERROR; Exit (NPP_New); end;
with MyDataP(instance.pdata)^ do begin {Set everything to safe values}
NWindP := nil;
Loaded:=false;
Mov:= nil;
MovContr:= nil;
MovFileRef:= 0;
with TheFile do begin
vRefNum:=0;
parID:= 0;
name:= '';
end;
with GraphicsState do begin
DidSave:= false;
PortChanged:= false;
end;
TempRegion:= NewRgn;
if TempRegion = nil then begin NPP_New:= NPERR_OUT_OF_MEMORY_ERROR; Exit (NPP_New); end;
CopyC2P (pluginType, s); {Find out what kind of a file this is}
WhatIsIt (s, MacFileType, Options.MediaKind);
{Set all options to default}
with Options do begin
CX:=true; CY:=true; AL:= false; AT:= false; {Center x and y}
F:=false; {Auto size (not fixed)}
case MediaKind of {Control settings}
'V': CS:=Auto; {Video - Auto control}
'S': CS:=None; {Still image - no control}
'A': CS:=Visible; {Audio - control}
end;
StartPosition:=0; {Start at begining by default}
PlayRate:=0; {Don't start auto-playing}
LP:= Once; {No looping}
Vol:= 0256; {Volume = 1 (16 bit fixed) }
Slide:=false; {Slideshow mode off}
case MediaKind of {HiQ settings}
'V': HighQ:= false; {Video - High quality (slow) off}
'S': HighQ:= true; {Still image - High quality on}
'A': HighQ:= false; {Audio - High quality off}
end;
UsePalette:=false; {Don't use custom palette}
{Override defaults with HTML options}
for i := 1 to argc do
begin
CopyC2P (argv^[i], V); {Git them C strings outa here!}
UpperString(V, true); {Case insensitve}
CopyC2P (argn^[i], N);
UpperString(N, true);
if N = 'PLACE' then
begin
if Pos('T', V) > 0 then begin CY:=false; AT:=true; end; {Top}
if Pos('B', V) > 0 then begin CY:=false; AT:=false; end; {Bottom}
if Pos('L', V) > 0 then begin CX:=false; AL:=true; end; {Left}
if Pos('R', V) > 0 then begin CX:=false; AL:=false; end; {Right}
if Pos('F', V) > 0 then F:=true; {Force fit}
end;
if N = 'CONTROL' then
begin
if Pos('H', V) > 0 then CS:= Hidden; {Hidden controller}
if Pos('V', V) > 0 then CS:= Visible; {Visible controller}
if Pos('0', V) > 0 then CS:= None; {No movie contallability}
if Pos('B', V) > 0 then CS:= Badge; {No controller, but put up the badge icon}
end;
if N = 'PLAY' then {PLAY=<integer percent>}
begin
StringToNum(V, PlayRate);
PlayRate := (PlayRate * 065536) div longint(0100); {Convert percent to fixed}
end;
if N = 'LOOP' then
begin
if Pos('L', V) > 0 then LP:= Linear;
if Pos('P', V) > 0 then LP:= Palidrome;
end;
if N = 'VOL' then {VOL=<integer percent>}
begin
StringToNum(V, NewVol);
Vol := (NewVol * longint(0256)) div longint(0100); {Convert percent to fixed}
end;
if N = 'HINTS' then
begin
if Pos('S', V) > 0 then Slide:=true; {Slideshow mode - all frames at High Q}
if Pos('Q', V) > 0 then HighQ:=true; {High Q mode}
if Pos('P', V) > 0 then UsePalette:=true; {Use custom palette}
end;
end; {argc loop}
if recalled <> nil then {If there are saved states then get them as an override}
with SavedDataPtrT(@recalled^.buf)^ do
begin
StartPosition:= LastTime; {These will be used at PrepMovie}
PlayRate:= LastRate;
Vol:= LastVol;
end;
end; {with Options}
end; {with MyDataP(instance.pdata)^}
NPP_New:= NPERR_NO_ERROR;
end;
{/------------------------------------------------------------------------------------
// NPP_Destroy:
//------------------------------------------------------------------------------------}
function NPP_Destroy (var instance:NPP; var save: NPSavedDataPtr):NPError;
var
unused:TimeRecord;
s:SavedDataPtrT;
TotalSize:integer;
begin
with MyDataP(instance.pdata)^ do
begin
if TempRegion <> nil then begin DisposeRgn (TempRegion); TempRegion:= nil; end;
if MovContr <> nil then
begin
TotalSize:=sizeof(NPSavedData)+sizeof(SavedDataT); {The size of Netscape's record plus mine at the end}
save:= NPSavedDataPtr (NPN_MemAlloc(TotalSize)); {Get memory for storage}
if save <> nil then
begin
s:=SavedDataPtrT(@save^.buf); {Put data at the position of the buf marker}
s^.LastTime:= GetMovieTime (Mov, unused); {Save the current movie time for next time}
if MCDoAction(MovContr, mcActionGetPlayRate, @s^.LastRate) <> noErr then {Save play speed}
s^.LastRate:=0;
if MCDoAction(MovContr, mcActionGetVolume, @s^.LastVol) <> noErr then {Save volume control}
s^.LastVol:=0;
save^.len := TotalSize;
end; {save <>nil}
end; {MovContr<> nil}
end;
CloseIt (MyDataP(instance.pdata)^);
NPN_MemFree(instance.pdata);
instance.pdata := nil;
NPP_Destroy:= NPERR_NO_ERROR;
end;
{/------------------------------------------------------------------------------------
// NPP_SetWindow:
//------------------------------------------------------------------------------------}
function NPP_SetWindow (var instance: NPP; NwindowP: NPWindowPtr): NPError;
begin
with MyDataP(instance.pdata)^ do begin
NWindP := NwindowP; {Save a pointer to Netscape's dynamic window structure}
check1:= NWindP^.window; {Redundancy to later check for corruption}
check2:= NWindP^.window^.port;
GraphicsState.PortChanged:= true; {Let SetupDrawState know that it needs to reset the graphics stuff}
end;
NPP_SetWindow:= NPERR_NO_ERROR;
end;
{/------------------------------------------------------------------------------------
// NPP_NewStream:
//------------------------------------------------------------------------------------}
function NPP_NewStream (var instance: NPP;
Mtype: NPMIMEType;
var stream: NPStream;
seekable: boolean;
var stype: integer):NPError;
begin
MyDataP(instance.pdata)^.Loaded:= false; {We╒re loading now}
stype:=NP_ASFILE; {Tell Netscape that I need a file.}
NPP_NewStream:= NPERR_NO_ERROR;
end;
{ ------------------------------------------------------------------------------------
NPP_WriteReady:
------------------------------------------------------------------------------------}
function NPP_WriteReady (var instance: NPP; var stream: NPStream): longint;
begin
NPP_WriteReady:= $0FFFFFFF; {Number of bytes ready to accept in NPP_Write() }
end; {Not like it matters, I don't do memory streams}
{ ------------------------------------------------------------------------------------
NPP_Write:
------------------------------------------------------------------------------------}
function NPP_Write (var instance: NPP; var stream: NPStream; offset:longint; len: longint; buffer: Ptr): longint;
begin
NPP_Write:= 0; {I don't do memory streams.}
end;
{ ------------------------------------------------------------------------------------
NPP_DestroyStream - Done loading
------------------------------------------------------------------------------------}
function NPP_DestroyStream (var instance: NPP; var stream: NPStream; reason: NPError) :NPError;
begin
if reason = NP_NOERR then with MyDataP(instance.pdata)^ do begin {Loading complete}
if OpenFromFile (MyDataP(instance.pdata)^) = noErr then {Open the movie file}
begin
Loaded := true; {OK}
NPP_DestroyStream:= NPERR_NO_ERROR;
end else begin {File didn't open}
CloseIt (MyDataP(instance.pdata)^);
NPP_DestroyStream:= NPERR_MODULE_LOAD_FAILED_ERROR;
end;
if Loaded & (noErr = PrepMovie (MyDataP(instance.pdata)^)) then {Get movie ready for playing}
begin;
NPP_DestroyStream:= NPERR_NO_ERROR; {OK}
end else
begin
CloseIt (MyDataP(instance.pdata)^); {Movie didn't prep}
NPP_DestroyStream:= NPERR_MODULE_LOAD_FAILED_ERROR;
end;
end else begin {Loading incomplete}
CloseIt (MyDataP(instance.pdata)^);
NPP_DestroyStream:= NPERR_MODULE_LOAD_FAILED_ERROR;
end;
end;
{ ------------------------------------------------------------------------------------
NPP_StreamAsFile:
------------------------------------------------------------------------------------}
procedure NPP_StreamAsFile (var instance: NPP; var stream: NPStream; fname: charstar);
var
name:Str255; {I hope the path isn't too long! }
begin
CopyC2P (fname,name); {Set up info for loading from a file}
with MyDataP(instance.pdata)^ do begin
if FSMakeFSSpec (0,0, name, TheFile) <> noErr then SysBeep (30);
end;
end;
{ ------------------------------------------------------------------------------------
NPP_Print:
------------------------------------------------------------------------------------}
procedure NPP_Print (var instance: NPP; var PrintInfo: NPPrint);
var
pic: PicHandle;
now: TimeValue;
unused: TimeScale;
bounds:Rect;
begin
with MyDataP(instance.pdata)^ do begin
if PrintInfo.mode = NP_FULL then begin
{
If we╒re fullscreen, we don╒t want to take over printing,
so return false. NPP_Print will be called again with
mode = NP_EMBED.
}
PrintInfo.fullPrint.pluginPrinted := false;
end
else {If not fullscreen, we must be embedded}
begin
with PrintInfo.embedPrint.window.window^ do
begin
SetOrigin (portx, porty);
with NWindP^.clipRect do SetRectRgn (TempRegion, left+portx, top+porty, right+portx, bottom+porty);
{SetClip (TempRegion);}
now:= MCGetCurrentTime (MovContr, unused);
GetMovieBox (Mov, bounds);
pic:= GetMoviePict (Mov, now);
if pic <> nil then begin
DrawPicture (pic, bounds);
KillPicture (pic);
end;
end;
end;
end;
end;
{ ------------------------------------------------------------------------------------
NPP_HandleEvent:
Mac-only.
------------------------------------------------------------------------------------}
function NPP_HandleEvent (var instance: NPP; var event: EventRecord): integer;
var
CompErr:ComponentResult;
Took:boolean;
begin
Took:=false;
if (@instance=nil) | (instance.pdata = nil) then begin NPP_HandleEvent:=0;Exit (NPP_HandleEvent); end;
with MyDataP(instance.pdata)^ do if Loaded then begin
if not Corruption (MyDataP(instance.pdata)^) then {Make sure Netscape isn't confused about the window}
begin
if event.what = getFocusEvent then {Activate controller}
begin
CompErr := MCDoAction(MovContr, mcActionActivate, nil);
Took:=true;
end;
{if event.what = loseFocusEvent then} {Deactivate controller, not handled because it requires an extra}
{begin} {mouse click to reactivate. }
{end;}
if event.what = updateEvt then
begin
{event.message:= ord(NWindP^.window^.port);} {Netscape doesn't make REAL event records.}
ControlledUpdate (MyDataP(instance.pdata)^ ,false); {Don't let MCIsPlayerEvent call BeginUpdate}
Took:=true;
end;
if (event.what = mouseDown) and (Options.CS = None) then Took:=true; {Mask mouse-down if Mouse control is off}
{if event.what = adjustCursorEven then ;} {No fancy cursor handling}
if (not Took) and (event.what < adjustCursorEven) then Took:= ControlledMovieEvent(MyDataP(instance.pdata)^, event) = 1; {Handle MacOS events}
end; {Integrity checked OK}
end; {With}
NPP_HandleEvent:=ord(Took);
end;
{And they viewed multimedia hapily ever after.}
{The }
end.